package cn.cagurzhan;

import com.alibaba.dashscope.aigc.conversation.Conversation;
import com.alibaba.dashscope.aigc.conversation.ConversationParam;
import com.alibaba.dashscope.aigc.conversation.ConversationResult;
import com.alibaba.dashscope.aigc.multimodalconversation.*;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import com.alibaba.dashscope.utils.Constants;
import java.util.Arrays;

/**
 * @author AjaxZhan
 */
@SpringBootTest
public class TestLLM {

    private static String sk_chatpgt = "";

    private static String sk_glm = "";

    // @Test
    // public void testGPT4(){
    //     //国内需要代理
    //     Proxy proxy = Proxys.http("127.0.0.1", 7890);
    //     //socks5 代理
    //     // Proxy proxy = Proxys.socks5("127.0.0.1", 1080);
    //
    //     ChatGPT chatGPT = ChatGPT.builder()
    //             .apiKey(sk_chatpgt)
    //             .proxy(proxy)
    //             .apiHost("https://api.openai.com/") //反向代理地址
    //             .build()
    //             .init();
    //
    //     String res = chatGPT.chat("写一段七言绝句诗，题目是：火锅！");
    //     System.out.println(res);
    // }

    @Test
    public void testZhipu() throws NoApiKeyException, InputRequiredException {
        Constants.apiKey="";
        Conversation conversation = new Conversation();
        String prompt = "你是一个农业灌溉的专家，我将给你一段包含土壤湿度、空气湿度、土壤温度、空气温度、紫外线强度、土壤PH、土壤导电率、和天气信息的JSON数据，请你根据这些数据返回给我一个合适的灌溉方案，要具体和给出理由。数据如下：\n" +
                "{\n" +
                "  \"土壤湿度\": 60,\n" +
                "  \"空气湿度\": 70,\n" +
                "  \"土壤温度\": 25,\n" +
                "  \"空气温度\": 28,\n" +
                "  \"紫外线强度\": 5,\n" +
                "  \"土壤PH\": 6.5,\n" +
                "  \"土壤导电率\": 0.8,\n" +
                "  \"天气信息\": \"多云\"\n" +
                "}\n";
        ConversationParam param = ConversationParam
                .builder()
                .model("qwen-1.8b-chat")
                .prompt(prompt)
                .build();
        ConversationResult result = conversation.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    @Test
    public void testVL() throws NoApiKeyException, UploadFileException {
        Constants.apiKey="";
        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessageItemImage userImage = new MultiModalMessageItemImage(
                "https://img1.baidu.com/it/u=3094136062,1233792491&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=887");
        MultiModalMessageItemText userText = new MultiModalMessageItemText("你是一位农业诊断专家，" +
                "请你根据图片判断描述这个农产品的情况，" + "在你给出的情况的基础上，以下是土壤的数据：" + "{\n" +
                "\t\t\"空气湿度\": 71,\n" +
                "\t\t\"空气温度\": 23.39999962,\n" +
                "\t\t\"co2\": 525,\n" +
                "\t\t\"灯光亮度\": 90,\n" +
                "\t\t\"temp_air\": 0,\n" +
                "\t\t\"air_state\": 592,\n" +
                "\t\t\"u_strength\": 0,\n" +
                "\t\t\"Kin\": 0,\n" +
                "\t\t\"Nin\": 0,\n" +
                "\t\t\"humi_air\": 0,\n" +
                "\t\t\"rain_state\": 4095,\n" +
                "\t\t\"Pin\": 0,\n" +
                "\t\t\"humi_ground\": 0,\n" +
                "\t\t\"PH\": 3,\n" +
                "\t\t\"地面温度\": 21.60000038,\n" +
                "\t\t\"ec\": 0\n" +
                "\t}" +
                "，请根据你描述的农产品情况和我给出的数据，给出这个农产品的灌溉意见");
        MultiModalConversationMessage userMessage =
                MultiModalConversationMessage.builder().role(Role.USER.getValue())
                        .content(Arrays.asList(userImage, userText)).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .model(MultiModalConversation.Models.QWEN_VL_CHAT_V1)
                .message(userMessage).build();
        MultiModalConversationResult result = conv.call(param);
        System.out.print(result);
    }
}
